Skip to content

dsh-huggingface: size a cached checkpoint for the LOAD, from its files - #19

Merged
vecnode merged 1 commit into
mainfrom
feat/hf-fit
Nov 28, 2026
Merged

vecnode merged 1 commit into
mainfrom
feat/hf-fit

Conversation

@vecnode

@vecnode vecnode commented Nov 28, 2026

Copy link
Copy Markdown
Owner

What this adds

hf_repo now answers the question a download size only half-answers, for any
repo that is already cached: will it run here?

Read from the files on disk — no model loaded, no Python, no network:

weights  = the sum of the weight files
params   = weights / bytes-per-parameter
KV/token = 2 x layers x kv_heads x head_dim x dtype_bytes
total    = weights + KV x context + max(512 MiB, 10% of the weights)

Pass freeBytes and the context table gains a FITS column; pass contexts to
choose the lengths; pass dtype to override. A repo that is not cached, or is
metadata only, gets no estimate and a sentence saying why — the attention
heads live in a config.json that was never downloaded.

Also folded in from the dropped transformers row: the multilingual text_config
nesting, and the KV formula's grouped-query-attention handling (num_key_value_heads
rather than falling back to all heads).

The finding that came out of testing it

A checkpoint's dtype is in its safetensors HEADER, not in its config. Both the
parameter count and the KV size divide or multiply by bytes-per-parameter, so

sentence-transformers/all-mpnet-base-v2   config states no torch_dtype, stores F32
  assumed fp16:  ~219M params, KV 36.0 KB/token
  header says:   ~109M params, KV 72.0 KB/token   <- matches the Hub's own 109M

The header is a u64 length plus JSON read from the FRONT of the file, so it costs
a few KB of I/O. When a config claims one dtype and the weights are another, the
answer now names the disagreement instead of silently believing the config.

Verification

packages/dsh-huggingface: node checks/check-huggingface-node.mjs   243 checks, 0 failed
scripts/checks/check-node-routes.mjs                               all node-route checks passed
scripts/checks/check-no-secrets.mjs                                OK
scripts/checks/check-scripts.mjs                                   OK

New assertions: the arithmetic against exact bytes (128 KiB/token for a
32-layer/8-KV-head/head_dim-128 shape), an fp32 fixture with a real safetensors
header
, a metadata-only repo with no fit, and a FITS / NO pair driven by
freeBytes. Live against the real cache: mpnet reports ~109M params at float32 (from the safetensors header) · KV 72.0 KB/token.

Numbers on the banner

The banner in assets/vncode-banner6.png already carries 35 plugins, 59
skills
from the previous PR, and that is confirmed against the last cut: v0.1.5
had exactly 33 packages / 51 SKILL.md files, so the convention is packages =
plugins, skills = SKILL.md. This PR adds no package and no skill, so the numbers
do not move — the banner and assets/banner.html are unchanged and correct.

The download size only half-answers "should I fetch this?". Once the bytes are on
disk the question becomes "will it run here", and every number that decides it is
already in the cache.

hf_repo now answers it for a cached repo, with no model loaded and no Python:

  weights  = the sum of the weight files
  params   = weights / bytes-per-parameter
  KV/token = 2 x layers x kv_heads x head_dim x dtype_bytes
  total    = weights + KV x context + max(512 MiB, 10% of the weights)

Pass freeBytes and the context table gets a FITS column; pass contexts to choose
the lengths. A repo that is not cached, or is metadata only, gets no estimate and
says why - the attention heads live in a config that was never downloaded.

The dtype is read from the SAFETENSORS HEADER, not from config.json, and that is
a measured finding rather than a preference: sentence-transformers/all-mpnet-base-v2
states no torch_dtype and stores F32, so an fp16 assumption reported ~219M
parameters for a 109M model and HALF its real KV cache (36 KB/token rather than
72). An fp16 config claiming fp16 weights is now also reported as a disagreement
rather than silently believed.

Checks: 243 in the package (up from 217) - the arithmetic asserted against exact
bytes, an fp32 fixture with a REAL safetensors header, a metadata-only repo with
no fit, and a FITS/NO pair. check-node-routes, check-no-secrets, check-scripts
all pass.
@vecnode
vecnode merged commit c8384c8 into main Nov 28, 2026
1 check passed
@vecnode
vecnode deleted the feat/hf-fit branch November 28, 2026 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant